// Copyright 2009 Pigasus.
// GNU GPL v2.
// Author: John Zhang and Jordan Rupprecht.

#include <fstream>
#include <sstream>
#include <string>

using namespace std;

string IntToString(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}

bool ReadStringFromFile(string filename, string &contents) {
  ifstream file_stream(filename.c_str());
  stringstream ss;
  ss << file_stream.rdbuf();

  if (!file_stream && !file_stream.eof()) {
    // Error reading file!
    return false;
  }

  contents = ss.str();
  return true;
}

bool WriteStringToFile(string filename, string &contents) {
  ofstream file_stream;
  file_stream.open(filename.c_str());
  file_stream << contents;
  file_stream.close();
  return true;
}
